package com.company;

import java.util.ArrayList;

public class Main {
    static ArrayList<StudentScore> studentScores = new ArrayList<>();

    public static void main(String[] args) {
        // 创建一些学生成绩对象并添加到列表中
        studentScores.add(new StudentScore("001", "张三", "女", 85, 90, 92));
        studentScores.add(new StudentScore("002", "李四", "男", 90, 88, 86));
        studentScores.add(new StudentScore("003", "王五", "女", 88, 92, 90));

        // 测试计算语文的最高分
        System.out.println("语文的最高分: " + getMaxLanguageScore());

        // 测试计算数学的平均分
        System.out.println("数学的平均分: " + getAverageMathScore());

        // 测试统计男生和女生的人数
        countGenders();

        // 测试根据英语成绩进行排序输出【从高到低】
        sortByEnglishScore();
    }

    // 遍历输出所有数据
    public static void showAll() {
        for (StudentScore studentScore : studentScores) {
            System.out.println(studentScore);
        }
    }

    // 计算语文的最高分
    public static int getMaxLanguageScore() {
        if (studentScores == null || studentScores.isEmpty()) {
            return 0;
        }
        int maxScore = studentScores.get(0).getLanguage();
        for (StudentScore studentScore : studentScores) {
            int currentScore = studentScore.getLanguage();
            if (currentScore > maxScore) {
                maxScore = currentScore;
            }
        }
        return maxScore;
    }

    // 计算数学的平均分
    public static double getAverageMathScore() {
        if (studentScores == null || studentScores.isEmpty()) {
            return 0;
        }
        int sum = 0;
        for (StudentScore studentScore : studentScores) {
            sum += studentScore.getMath();
        }
        return (double) sum / studentScores.size();
    }

    // 统计男生和女生的人数
    public static void countGenders() {
        int maleCount = 0;
        int femaleCount = 0;
        for (StudentScore studentScore : studentScores) {
            if ("男".equals(studentScore.getSex())) {
                maleCount++;
            } else if ("女".equals(studentScore.getSex())) {
                femaleCount++;
            }
        }
        System.out.println("男生人数: " + maleCount);
        System.out.println("女生人数: " + femaleCount);
    }

    // 根据英语成绩进行排序输出【从高到低】
    public static void sortByEnglishScore() {
        studentScores.sort((s1, s2) -> s2.getEnglish() - s1.getEnglish());
        for (StudentScore studentScore : studentScores) {
            System.out.println(studentScore);
        }
    }
}

class StudentScore {
    // 学号属性
    private String studentID;
    // 姓名属性
    private String name;
    // 性别属性
    private String sex;
    // 语文属性
    private int language;
    // 数学属性
    private int math;
    // 英语属性
    private int english;

    @Override
    public String toString() {
        return "StudentScore{" +
                "studentID='" + studentID + '\'' +
                ", name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", language=" + language +
                ", math=" + math +
                ", english=" + english +
                '}';
    }

    public StudentScore() {
    }

    public StudentScore(String studentID, String name, String sex, int language, int math, int english) {
        this.studentID = studentID;
        this.name = name;
        this.sex = sex;
        this.language = language;
        this.math = math;
        this.english = english;
    }

    public String getStudentID() {
        return studentID;
    }

    public void setStudentID(String studentID) {
        this.studentID = studentID;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getLanguage() {
        return language;
    }

    public void setLanguage(int language) {
        this.language = language;
    }

    public int getMath() {
        return math;
    }

    public void setMath(int math) {
        this.math = math;
    }

    public int getEnglish() {
        return english;
    }

    public void setEnglish(int english) {
        this.english = english;
    }

}